package com.lc.ei.controller;

import com.alibaba.excel.EasyExcel;
import com.lc.ei.config.listener.ExcelListener;
import com.lc.ei.service.DataService;
import com.study.common.res.ApiResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.*;

/**
 * @description: some desc
 * @author: LChuang
 * @date: 2023/9/18 10:32
 */
@RestController
@RequestMapping("/dynamic/excel")
public class DynamicExcelController {

    @Resource
    private ExcelListener excelListener;

    @Resource
    private DataService dataService;

    @PostMapping("/import")
    public ApiResult importFile(@RequestParam("file") MultipartFile file) throws IOException {
        dataService.parseData(file);
        return ApiResult.success();
    }

    @PostMapping("/importTest")
    public ApiResult importTest(@RequestParam("file") MultipartFile file) throws IOException {
        EasyExcel.read(file.getInputStream(), excelListener).sheet().doRead();

        List<Map<Integer, Map<Integer, String>>> dataList = excelListener.getDataList();
        Map<Integer, String> headTitleMap = excelListener.getHeadTitleMap();
        Map<Integer, Map<String, String>> modifyDataMap = excelListener.getModifyDataMap();
        System.out.println(dataList);
        System.out.println("-----------------------------------------------------------------------------------------------------------------------------");
        System.out.println(modifyDataMap);
        System.out.println("-----------------------------------------------------------------------------------------------------------------------------");
        System.out.println(headTitleMap);
        return ApiResult.success();
    }

}
